package API.File.Practise;

import java.io.File;
import java.util.ArrayList;

import static API.File.Practise.MainFile.mainFilePath;

public class _3FindFileEndWithTxtTraversably {
    public static void main(String[] args) {
        File file = new File(mainFilePath);
        recursion(file).forEach(System.out::println);
    }

    public static ArrayList<File> recursion(File file) {
        File[] files = file.listFiles();
        ArrayList<File> list = new ArrayList<>();
        if (files != null) {
            for (File f : files) {
                if (f.isFile()) {
                    list.add(f);
                } else if (f.isDirectory()) {
                    list.addAll(recursion(f));
                }
            }
            return list;
        } else {
            return null;
        }
    }
}
